package cn.gyxy.exception;

import org.apache.shiro.ShiroException;
import org.apache.shiro.authc.IncorrectCredentialsException;
import org.apache.shiro.authc.UnknownAccountException;
import org.apache.shiro.authz.AuthorizationException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class Mapperexception extends  RuntimeException {

    //shiro异常处理！
    @ExceptionHandler(ShiroException.class)
    public String doShiroException(ShiroException e) {
        if (e instanceof UnknownAccountException || e instanceof IncorrectCredentialsException)
            return "用户名或密码不正确";
        else if (e instanceof AuthorizationException) return "用户权限不足";
        else return "认证失败，请稍后重试";
    }
    //密码账号密码以及改密异常
    @ExceptionHandler(IllegalArgumentException.class)
    public  String errorException1( IllegalArgumentException e){

        return e.getMessage();
    }

    //其他异常
    @ExceptionHandler(Exception.class)
    public  String errorException2( Exception e){

        return "系统出错或输入异常！"+e.getMessage();
    }
}
